<template>
	<view class="select-job-standard-main">
		<view class="top-search new-top-search">
			<view class="downMenu">
				<picker @change="bindPickerChange" :value="checkGroupIndex" :range="groupList" range-key="name">
					<view class="text-dowm">
						<text>所属分组</text>
						<image
							src="https://fireware-1257276602.cos.ap-guangzhou.myqcloud.com/fsw-wx-lmini/icons/icons/Polygon_2.png"
							mode="" />
					</view>
				</picker>
			</view>
			<view class="search add-border w-250">
				<input class="weui-input w460" v-model="query.name" @confirm="getList(false)" confirm-type="search"
					placeholder="请输入" />
				<image @click="clearInputHandle" class="w36 h36 mr20"
					src="https://fireware-1257276602.cos.ap-guangzhou.myqcloud.com/fsw-wx-lmini/icons/delico.png"
					mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload=""></image>
			</view>
		</view>
		<scroll-view @scrolltolower="scrolltolowerHandle" scroll-y="true" class="device-body">
			<view @click="checkGroupHandle(item)" class="item global_box" v-for="(item,index) in dataList"
				:key="item.id">
				<view class="left">
					<view class="text-1">
						{{ item.name }}
					</view>
					<view class="text-2">
						所属分组:{{ groupList[checkGroupIndex].name }}
					</view>
				</view>
				<view class="right">
					<radio :checked="checkedItemId==item.id" color="#fff"></radio>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		request
	} from "../../request/index.js";

	export default {
		data() {
			return {
				checkedItemId: {},
				query: {
					pageIndex: 1,
					pageSize: 10,
					groupId: "",
					name: ""
				},
				dataList: [],
				groupList: [],
				scrollStatus: false,
				checkGroupIndex: 0,
				total: 0,
				pages: 0
			}
		},
		async mounted() {
			let routes = getCurrentPages();
			let curRouteNow = routes[routes.length - 1]
			this.checkedItemId = curRouteNow.options.procedureId || ""

			await this.getClass()
			this.getList()
		},
		methods: {
			async scrolltolowerHandle() {
				if (this.scrollStatus || (this.query.pageIndex == this.pages)) return

				this.scrollStatus = true
				this.query.pageIndex = this.query.pageIndex + 1
				const res = await this.getList(true)

				this.dataList = [...this.dataList, ...res.payload.records]
				this.pages = res.payload.pages
				this.total = res.payload.total
				this.scrollStatus = false
			},
			bindPickerChange(e) {
				this.checkGroupIndex = e.detail.value //  获取菜单选中数据下标
				this.query.groupId = this.groupList[this.checkGroupIndex].id
				this.getList()
			},
			clearInputHandle() {
				this.query.name = ""
				this.getList()
			},
			checkGroupHandle(item) {
				this.checkedItemId = item.id

				let routes = getCurrentPages();
				let curRouteNow = routes[routes.length - 1]
				let curRouteBefore = routes[routes.length - 2]
				//  将工序id传递出去
				let obj = curRouteBefore.$vm.workOrderObjects[curRouteNow.options.index]
				this.$set(obj, 'procedureId', item.id)
				this.$set(obj, 'procedureName', item.name)
				uni.navigateBack({
					delta: 1
				})
			},
			async getClass() {
				const res = await request({
					url: "api/oct/wemini/bus/workOrder/findProcedureGroupList",
					method: "POST",
					data: {}
				})
				if (res.status == 0) {
					this.groupList = res.payload
				} else {
					uni.showToast({
						title: res.description,
						icon: 'none',
						duration: 1000,
						success: (res) => {

						},
					})
				}
			},
			async getList(status) {
				const res = await request({
					url: "api/oct/wemini/bus/workOrder/findProcedurePage",
					method: "POST",
					data: this.query
				})
				if (res.status == 0) {
					if (status) return res
					else {
						this.dataList = res.payload.records
						this.pages = res.payload.pages
						this.total = res.payload.total
					}
				} else {
					uni.showToast({
						title: res.description,
						icon: 'none',
						duration: 1000,
						success: (res) => {

						},
					})
				}
			},
		}
	}
</script>

<style lang="less">
	.select-job-standard-main {
		background-color: #f2f6ff;
		padding: 10rpx 30rpx 0;
		font-size: 28rpx;

		.device-body {
			height: calc(100vh - 130rpx);
			overflow: scroll;

			.item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 20rpx 0;

				.text-1 {
					font-size: 28rpx;
					// line-height: 40rpx;
				}

				.text-2 {
					font-size: 24rpx;
					color: #A2AFD0;
					// margin-top: 20rpx;
					line-height: 70rpx;
				}

				.text-3 {
					font-size: 24rpx;
					color: #A2AFD0;
				}
			}
		}

		.new-top-search {
			width: auto !important;
			background-color: transparent !important;
		}

		.add-border {
			border: 3rpx solid @main_bg;
			position: relative;


		}
		
		.text-dowm {
			display: inline-block;
			width: 140rpx;
			color: #0A1B57;
			font-weight: 700;
			>image{
				margin-left: 10rpx;
				width: 18rpx;
				height: 11rpx;
				vertical-align: middle;
			}
		}

		.footer {
			height: 88rpx;
			width: 100vw;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			background-color: @main_bg;
			position: fixed;
			left: 0;
			bottom: 0;
		}
	}
</style>